from sklearn import datasets, preprocessing
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

X, y = datasets.load_iris(return_X_y=True)

# X = preprocessing.StandardScaler().fit_transform(X)  # 标准化

# X = preprocessing.MinMaxScaler().fit_transform(X)  # 归一化normalnization  对异常数据十分敏感
# X = preprocessing.minmax_scale(X)  # 同上

# X =preprocessing.RobustScaler().fit_transform(X)  # 处理异常值

# X = preprocessing.maxabs_scale(X)  # 稀疏矩阵：除最大数的绝对值 放缩到[-1,1]

from sklearn.impute import SimpleImputer  # 缺失值的库
X = SimpleImputer().fit_transform(X)
"""
处理缺失值
SimpleImputer (missing_values=np.nan, strategy='mean’, fill_value=None，copy=True)
strategy=’mean’ 'median'  'most_frequent'  'constant'

data.loc[:,"Age"] = data.loc[:,"Age"].fillna(data.loc[:,"Age"].median())
#.fillna 在DataFrame里面直接进行填补

data.dropna(axis=0,inplace=True)
#.dropna(axis=0)删除所有有缺失值的行，.dropna(axis=1)删除所有有缺失值的列
#参数inplace，为True表示在原数据集上进行修改，为False表示生成复制对象，不修改原数据，默认False

"""


x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.13, random_state=13)
knn = KNeighborsClassifier().fit(x_train, y_train)
print(knn.score(x_test, y_test))

